package common.sysconfig;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitmqConfig {

    public static final String QUEUE_INFORM_FAST = "queue_inform_fast";
    public static final String QUEUE_INFORM_NORMAL = "queue_inform_normal";
    public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
    public static final String ROUTINGKEY_FAST = "inform.#.fast.#";
    public static final String ROUTINGKEY_NORMAL = "inform.#.normal.#";

    @Bean(EXCHANGE_TOPICS_INFORM)
    public Exchange EXCHANGE_TOPICS_INFORM() {
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
    }

    @Bean(QUEUE_INFORM_FAST)
    public Queue QUEUE_INFORM_FAST() {
        return new Queue(QUEUE_INFORM_FAST);
    }


    @Bean(QUEUE_INFORM_NORMAL)
    public Queue QUEUE_INFORM_NORMAL() {
        return new Queue(QUEUE_INFORM_NORMAL);
    }


    @Bean
    public Binding BINDING_QUEUE_INFORM_FAST(@Qualifier(QUEUE_INFORM_FAST) Queue queue,
                                             @Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_FAST).noargs();
    }

    @Bean
    public Binding BINDING_QUEUE_INFORM_NORMAL(@Qualifier(QUEUE_INFORM_NORMAL) Queue queue,
                                               @Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_NORMAL).noargs();
    }
}